var config = require ('../config.js');
var randomUtils = require ('./utils/randomUtils');
var logUtils = require ('./utils/logUtils');
var youShi = require ('./apps/youShi/index');
var wuKong = require ('./apps/wuKong/index');
var baiDuJiSu = require ('./apps/baiDuJiSu/index');
var xiGua = require ('./apps/xiGua/index');
var kuaiShouJiSu = require ('./apps/kuaiShouJiSu/index');
var douYin = require ('./apps/douYin/index');
var touTiao = require ('./apps/touTiao/index');
var hongGuo = require ('./apps/hongGuo/index');
const appUtils = require ('./utils/appUtils.js');

var apps = [
  //prettier-ignore
  // youShi,
  // wuKong,
  // douYin,
  // kuaiShouJiSu,
  // xiGua,
  // baiDuJiSu,
  // hongGuo,
  // touTiao,
  // xiGua,

  touTiao,
  wuKong,
];
function start () {
  apps.forEach (function (app) {
    app.openCount = 0;
  });
  while (true) {
    for (var index = 0; index < apps.length; index++) {
      var app = apps[index];
      var isIgnoreApp = config.ignoreApps.find (ignoreApp => {
        return ignoreApp == app.name;
      });
      if (isIgnoreApp) {
        console.log (`${app.name} is ignore`);
        logUtils.log (app.name + '被跳过');
      } else {
        var canRun = app.canRun ();
        app.main ();
        sleep (randomUtils.getRandom (2, 3, 1000));
        if (canRun) {
          appUtils.closeAll ();
        }
      }
      sleep (randomUtils.getRandom (8, 15, 1000));
    }
  }
}

start ();
